package com.zone.session;

import com.zone.builder.xml.XmlConfigBuild;
import com.zone.session.defaults.DefaultSqlSessionFactory;
import org.dom4j.DocumentException;

import java.io.Reader;

/**
 * @author: zongzi
 * @description: TODO
 * @date: 2023/12/10
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(Reader reader) {
        XmlConfigBuild xmlConfigBuild = new XmlConfigBuild();
        try {
            Configuration configuration = xmlConfigBuild.parse(reader);
            return this.build(configuration);
        } catch (DocumentException e) {
            throw new RuntimeException(e);
        }
    }


    public SqlSessionFactory build(Configuration configuration) {
        return new DefaultSqlSessionFactory(configuration);
    }
}
